package com.hyjx.framework.service.extend;

import com.hyjx.framework.common.util.SpringBeanUtil;
import com.hyjx.framework.component.customquery.CustomQueryService;
import com.hyjx.framework.uc.user.UserModel;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by Peter on 2017/4/25.
 */
@Service("userExtendService")
public class UserExtendServiceImpl implements IUserExtend {
    
    @Override
    public void beforeAdd(UserModel user) {
    
    }
    
    @Override
    public void afterAdd(UserModel user) {
    
    }
    
    @Override
    public void beforeUpdate(UserModel user) {
    
    }
    
    @Override
    public void afterUpdate(UserModel user) {
    
    }
    
    @Override
    public void beforeDelete(String userId) {
    
    }
    
    @Override
    public void afterDelete(String userId) {
    
    }
    
    @Override
    public boolean isRoleNameUnique(String roleId, String roleName) {
        CustomQueryService querySrv = (CustomQueryService) SpringBeanUtil.getBean("customQueryServiceImpl");
        String sql = "select case when count(*) >0 then '1' else '0' end as CC from sys_right_role where role_id<>'" + roleId + "' and role_name ='" + roleName + "'";
        List<Map<String, String>> list = querySrv.queryMap(sql);
        
        boolean result = true;
        if (list != null && list.size() != 0) {
            String cc = list.get(0).get("CC");
            if ("0".equals(cc)) {
                result = true;
            } else {
                result = false;
            }
        }
        
        return result;
    }
    
    @Override
    public boolean isUserAccountUnique(String userId, String userAccount) {
        CustomQueryService querySrv = (CustomQueryService) SpringBeanUtil.getBean("customQueryServiceImpl");
        String sql = "select case when count(*) >0 then '1' else '0' end as DD from sys_right_user where user_id<>'" + userId + "' and user_account ='" + userAccount + "' and status=1";
        List<Map<String, String>> list = querySrv.queryMap(sql);
        
        boolean result = true;
        if (list != null && list.size() != 0) {
            String cc = list.get(0).get("DD");
            if ("0".equals(cc)) {
                result = true;
            } else {
                result = false;
            }
        }
        return result;
    }
}
